﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Diagnostics;
using System.IO;
using BesAsm.Emgaats.Core;

namespace BesAsm.Emgaats.Launcher
{
  class Program
  {
    static void Main(string[] args)
    {
      Process p = new Process();
      string arcHome = Environment.GetEnvironmentVariable("arcgishome");
      if (!Directory.Exists(arcHome))
        arcHome = @"c:\program files\arcgis\desktop10.1";

      string arcPath = Path.Combine(arcHome, "bin");
      string arcExe = Path.Combine(arcPath, "arcmap.exe");

      if (!File.Exists(arcExe))
      {
        Console.WriteLine("Error loading EMGAATS 3: Unable to find ArcMap.exe. Expected location was " + arcExe);
        Console.ReadKey();
        return;
      }

      try
      {
        string templateMxd = "\"" + EmgaatsCoreExtension.GetTemplateMxdFileName() + "\"";

        p.StartInfo.FileName = arcExe;
        p.StartInfo.Arguments = templateMxd + @" /show_emgaats";

        p.StartInfo.WindowStyle = ProcessWindowStyle.Maximized;

        p.Start();
      }
      catch (Exception ex)
      {
        Console.WriteLine("Error loading EMGAATS 3: Unable to start ArcMap.exe.");
        Console.WriteLine(ex.Message);
        Console.ReadKey();
      }
    }
  }
}
